<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="common/header.jsp"%>
<div class="clearfix"></div>
<div class="row">
	<div class="col-md-12">
		<div class="x_panel">
			<div class="x_title">
				<h2>
					APP 信息管理维护 <i class="fa fa-user"></i><small>${devUser.devname}
					- 您可以通过搜索或者其他的筛选项对APP的信息进行修改、删除等管理操作。^_^</small>
				</h2>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<form method="post" id="form1" action="${pageContext.request.contextPath}/searchApp">
					<input type="hidden" name="page" id="setPage" value="1" />
					<ul>
						<li>
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">软件名称</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input name="querySoftwareName" type="text" class="form-control col-md-7 col-xs-12" value="${querySoftwareName }">
								</div>
							</div>
						</li>

						<li>
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">APP状态</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<select id="queryStatus" name="queryStatus" class="form-control">
										<option value="">请选择</option>
									</select>
								</div>
							</div>
						</li>
						<li>
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">所属平台</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<select id="queryFlatformId" name="queryFlatformId" class="form-control">
										<option value="">--请选择--</option>
									</select>
								</div>
							</div>
						</li>
						<li>
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">一级分类</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<select id="queryCategoryLevel1" name="queryCategoryLevel1" class="form-control">
										<option value="">--请选择--</option>
									</select>
								</div>
							</div>
						</li>
						<li>
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">二级分类</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input type="hidden" name="categorylevel2list" id="categorylevel2list"/>
									<select name="queryCategoryLevel2" id="queryCategoryLevel2" class="form-control">
										<option value="">--请选择--</option>
									</select>
								</div>
							</div>
						</li>
						<li>
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">三级分类</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<select name="queryCategoryLevel3" id="queryCategoryLevel3" class="form-control">
										<option value="">--请选择--</option>
									</select>
								</div>
							</div>
						</li>
						<li><button type="submit" class="btn btn-primary"> 查 &nbsp;&nbsp;&nbsp;&nbsp;询 </button></li>
					</ul>
				</form>
			</div>
		</div>
	</div>
	<div class="col-md-12 col-sm-12 col-xs-12">
		<div class="x_panel">
			<div class="x_content">
				<p class="text-muted font-13 m-b-30"></p>
				<div id="datatable-responsive_wrapper"
					 class="dataTables_wrapper form-inline dt-bootstrap no-footer">
					<div class="row">
						<div class="col-sm-12">
							<a href="${pageContext.request.contextPath}/jsp/developer/appinfoadd.jsp" class="btn btn-success btn-sm">新增APP基础信息</a>
							<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline collapsed"
								   cellspacing="0" width="100%" role="grid" aria-describedby="datatable-responsive_info" style="width: 100%;">
								<thead>
								<tr role="row">
									<th class="sorting_asc" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="First name: activate to sort column descending"
										aria-sort="ascending">软件名称</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										APK名称</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										软件大小(单位:M)</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										所属平台</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										所属分类(一级分类、二级分类、三级分类)</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										状态</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										下载次数</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										最新版本号</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										style="width: 124px;"
										aria-label="Last name: activate to sort column ascending">
										操作</th>
								</tr>
								</thead>
								<tbody>
								<c:forEach var="appInfo" items="${pageInfo.list }" varStatus="status">
									<tr role="row" class="odd">
										<td tabindex="0" class="sorting_1">${appInfo.softwarename}</td>
										<td>${appInfo.apkname }</td>
										<td>${appInfo.softwaresize }</td>
										<td>${appInfo.ptname}</td>
										<td>${appInfo.cname1 } -> ${appInfo.cname2 } -> ${appInfo.cname3 }</td>
										<td><span>${appInfo.sname }</span></td>
										<td>${appInfo.downloads }</td>
										<td>${appInfo.versionid }</td>
										<td name="td9">
											<div class="btn-group">
												<button type="button" class="btn btn-danger">点击操作</button>
												<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
													<span class="caret"></span>
													<span class="sr-only">Toggle Dropdown</span>
												</button>
												<ul class="dropdown-menu" role="menu">
													<li>
														<c:choose>
															<c:when test="${appInfo.status == 2 || appInfo.status == 5}">
																<a name="upJia" appid="${appInfo.id}" class="saleSwichOpen" saleSwitch="open" data-toggle="tooltip" data-placement="top" title="" data-original-title="恭喜您，您的审核已经通过，您可以点击上架发布您的APP">上架</a>
															</c:when>
															<c:when test="${appInfo.status == 4}">
																<a name="upJia" appid="${appInfo.id}" class="saleSwichClose" saleSwitch="close"  data-toggle="tooltip" data-placement="top" title="" data-original-title="您可以点击下架来停止发布您的APP，市场将不提供APP的下载">下架</a>
															</c:when>
														</c:choose>
													</li>
													<li><a class="addVersion" href="${pageContext.request.contextPath}/goAddVersion?id=${appInfo.id}" data-toggle="tooltip" data-placement="top" title="" data-original-title="新增APP版本信息">新增版本</a>
													</li>
													<li><a class="modifyVersion"
														   data-toggle="tooltip" data-placement="top" title="" data-original-title="修改APP最新版本信息">修改版本</a>
													</li>
													<!--判断当app信息的状成为待审核和审核未能过显示修改-->
													<c:if test="${appInfo.status==1 || appInfo.status==3}">
														<li><a href="${pageContext.request.contextPath}/editAppInfo?id=${appInfo.id}"  class="modifyAppInfo" data-toggle="tooltip" data-placement="top" title="" data-original-title="修改APP基础信息">修改</a></li>
													</c:if>
													<li><a  class="viewApp" data-toggle="tooltip" data-placement="top" title="" data-original-title="查看APP基础信息以及全部版本信息">查看</a></li>
													<li><a  class="deleteApp" href="javascript:if(confirm('你确定想删除吗?')) location.href='${pageContext.request.contextPath}/deleteAppInfo?appId=${appInfo.id}&path=${appInfo.logopicpath}';" data-toggle="tooltip" data-placement="top" title="" data-original-title="删除APP基础信息以及全部版本信息">删除</a></li>
												</ul>
											</div>
										</td>
									</tr>
								</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-5">
							<div class="dataTables_info" id="datatable-responsive_info"
								 role="status" aria-live="polite">共${pageInfo.total }条记录
								${pageInfo.pageNum}/${pageInfo.pages}页</div>
						</div>
						<div class="col-sm-7">
							<div class="dataTables_paginate paging_simple_numbers"
								 id="datatable-responsive_paginate">
								<ul class="pagination">
									<c:if test="${pageInfo.pageNum > 1}">
										<li class="paginate_button previous"><a
												href="javascript:page_nav(1);"
												aria-controls="datatable-responsive" data-dt-idx="0"
												tabindex="0">首页</a>
										</li>
										<li class="paginate_button "><a
												href="javascript:page_nav(${pageInfo.pageNum-1});"
												aria-controls="datatable-responsive" data-dt-idx="1"
												tabindex="0">上一页</a>
										</li>
									</c:if>
									<c:if test="${pageInfo.pageNum < pageInfo.pages }">
										<li class="paginate_button "><a
												href="javascript:page_nav(${pageInfo.pageNum+1 });"
												aria-controls="datatable-responsive" data-dt-idx="1"
												tabindex="0">下一页</a>
										</li>
										<li class="paginate_button next"><a
												href="javascript:page_nav(${pageInfo.pages });"
												aria-controls="datatable-responsive" data-dt-idx="7"
												tabindex="0">最后一页</a>
										</li>
									</c:if>
								</ul>
							</div>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
</div>
<%@include file="common/footer.jsp"%>
<script language="JavaScript" >
    $(function(){   //加载事件
                    //1.发送异步请求加载app状态
                    //("服务器地址",参数,回调回调,"json");
        $.post("${pageContext.request.contextPath}/getAppState",null,function(data){
            //循环数据生成option添加下拉列表
            for(var i=0;i<data.length;i++){
                //创建option
                var option=$("<option value='"+data[i].valueid+"'>"+data[i].valuename+"</option>");
                $("#queryStatus").append(option);
            }
            //设置App状态---下拉列表选中项(发送查找请求后将选中项回显到页面)
            $("#queryStatus").val(${condition.queryStatus});
        },"json");

        //2.发送异步请求加载平台分类
        $.post("${pageContext.request.contextPath}/getFlatform",null,function (data) {
            for (var j=0;j<data.length;j++){
                var option=$("<option value='"+data[j].valueid+"'>"+data[j].valuename+"</option>");
                $("#queryFlatformId").append(option);
            }
            //设置所属平台---下拉列表选中项(发送查找请求后将选中项回显到页面)
            $("#queryFlatformId").val(${condition.queryFlatformId});
        },"json");

        //3.发送异步请求加载一级分类...
        $.post("${pageContext.request.contextPath}/getCategory",null,function (data) {
            //动态加载下拉列表的选项
            for (var i=0;i<data.length;i++){
                var node=$("<option value='"+data[i].id+"'>"+data[i].categoryname+"</option>");
                //将node添加到select标签中   添加子节点
                $("#queryCategoryLevel1").append(node);
            }
            //设置*一级分类---下拉列表选中项(发送查找请求后将选中项回显到页面)
            $("#queryCategoryLevel1").val(${condition.queryCategoryLevel1});
            loadCategoryLevel2()
        },"json");


        // 二级分类的数据
        //4.当选择一级分类时，触发onchange事件，加载二级分类
        $("#queryCategoryLevel1").change(loadCategoryLevel2);

        function loadCategoryLevel2() {
            //4.1获取一级分类的值
            var parentId=$("#queryCategoryLevel1").val();

            $("#queryCategoryLevel2>option:gt(0)").remove();  //清空原有的下拉列表项
            $("#queryCategoryLevel3>option:gt(0)").remove();
            if (parentId!=""){

                //4.2发送异步请求通过分类的id查询子类
                //参数的格式:{"请求参数名称":参数值,"请求参数名称":参数值...}
                $.post("${pageContext.request.contextPath}/getCategory",{"id":parentId},function (data) {
                    //动态加载下拉列表的选项
                    for (var i=0;i<data.length;i++){
                        var node=$("<option value='"+data[i].id+"'>"+data[i].categoryname+"</option>");
                        //将node添加到select标签中   添加子节点
                        $("#queryCategoryLevel2").append(node);
                    }
                    //设置二级分类的下拉列表选中项
                    $("#queryCategoryLevel2").val(${condition.queryCategoryLevel2});
                    loadCategoryLevel3();
                },"json");
            }
        }

        //加载三级分类的数据
        $("#queryCategoryLevel2").change(loadCategoryLevel3);
        function loadCategoryLevel3() {
            //4.1获取二级级分类的值
            var parentId=$("#queryCategoryLevel2").val();
            $("#queryCategoryLevel3>option:gt(0)").remove();  //清空原有的下拉列表项
            if (parentId!=""){
                //4.2发送异步请求通过分类的id查询子类
                $.post("${pageContext.request.contextPath}/getCategory",{"id":parentId},function (data) {
                    //动态加载下拉列表的选项
                    for (var i=0;i<data.length;i++){
                        var node=$("<option value='"+data[i].id+"'>"+data[i].categoryname+"</option>");
                        //将node添加到select标签中   添加子节点
                        $("#queryCategoryLevel3").append(node);
                    }
                    //设置三级分类的下拉列表选中项
                    $("#queryCategoryLevel3").val(${condition.queryCategoryLevel3});
                },"json");
            }
        }
    });

    //分页导航
	function page_nav(pageNum) {
		$("#setPage").val(pageNum)
		$("#form1").submit();
	}

	//上架和下架
    $(function(){
	$("a[name='upJia']").click(function () {
	    //发送异步请求
	    var id=$(this).attr("appid");  //获取当前标签的appid值
		//定位到显示状态的单元格
	    var stateTd=$(this).parents("[name='td9']").prev().prev().prev();
	    var aNode=$(this);
        if(aNode.html()=="上架")
        {
            $.post("${pageContext.request.contextPath}/upDownApp"
                ,{"id":id,"state":4},function(data){
                    if(data.result>0){
                        //刷新方式更新信息   location.reload();
                        stateTd.html("已上架");
                        aNode.html("下架");
                        //alert("成功");  //刷新
                    } else{
                        alert("失败");
                    }
                },"json");
        }else{
            $.post("${pageContext.request.contextPath}/upDownApp"
                ,{"id":id,"state":5},function(data){
                    if(data.result>0){
                        //刷新方式更新信息   location.reload();
                        stateTd.html("已下架");
                        aNode.html("上架");
                        //alert("成功");  //刷新
                    } else{
                        alert("失败");
                    }
                },"json");
        }
	});
    });
</script>
